package com.adnaan.backend.controller.common;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.annotation.SaIgnore;
import cn.dev33.satoken.annotation.SaMode;
import com.adnaan.backend.common.annotation.RestControllerMapping;
import com.adnaan.backend.common.mail.service.EmailService;
import com.adnaan.backend.common.model.Result;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.HashMap;
import java.util.Map;

/**
 * author: adnaan
 * create: 2025-01-20 21:38
 * Description:
 */
@RestControllerMapping("/test")
public class AuthTestController {

    @Resource
    private EmailService emailService;

    @GetMapping
    @SaCheckRole(value = {"ADMIN", "USER"}, mode = SaMode.OR)
    @SaCheckPermission(value = {"system:user:select", "test2"}, mode = SaMode.OR)
    public Result<String> test() {
        return Result.success("测试通过");
    }


    @GetMapping("/email")
    @SaIgnore
    public Result<String> email() {
        try {
            Map<String, Object> model = new HashMap<>();
            model.put("username", "张三");
            model.put("email", "zhangsan@example.com");
            model.put("approvalTime", "2024-03-19 10:00:00");
            model.put("loginUrl", "http://your-domain.com/login");
            model.put("logo", "http://your-domain.com/logo.png");
            model.put("year", "2024");
            model.put("companyName", "中草药识别系统");
            emailService.sendTemplateMail("1662877157@qq.com", "账号申请通过通知", "account-approved.html", model);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.success();
    }
}
